package com.training.java.core.exceptionhandling;

import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

public class ExceptionDemo3 {

	public static void main(String[] args)  
	{
		try{
	    ExceptionDemo3 ed3= new ExceptionDemo3();
	    ed3.printToFile();
		}
		catch(IOException ex)
		{
			System.out.println("i am in main method's catch block");
			ex.printStackTrace();
		}
		catch(NullPointerException ex1)
		{
			System.out.println("i am in another catch block.");
			ex1.printStackTrace();
		}
		

	}
	
	public void printToFile() throws IOException,NullPointerException 
	{
	
		FileWriter fileWriter = new FileWriter("d:\\javatrainingbyreenu.txt");
		//FileWriter fileWriter = new FileWriter("");
		//PrintWriter out = new PrintWriter(fileWriter);
		PrintWriter out =null;
		out.write("I am doing exception Handling.\r\n");
		//out.println();
		out.write("This should come in next line. \r\n");
		//out.println();
		out.write("i want this in next line.\r\n");
		//out.println();
		out.append("jkjlldksld");
		//out.flush();
		out.close();
		
	}

}
